home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ptime_10.zip / HACKMEM.ASM < prev    next >
Assembly Source File  |  1992-10-04  |  2KB  |  99 lines

  1.         ideal
  2.  
  3. struc        mcb
  4. signature    db    ?
  5. addressPSP    dw    ?
  6. blockSize    dw    ?
  7. reserved    db    3 dup (?)
  8. programName    db    8 dup (?)
  9. ends        mcb
  10.  
  11. segment        newBlockSeg at 0
  12. newBlock    mcb ?
  13. ends        newBlockSeg
  14.  
  15. segment        oldBlockSeg at 0
  16. oldBlock    mcb ?
  17. ends        oldBlockSeg
  18.  
  19. ;        DOS calls
  20. getPSP        equ    62h
  21.  
  22. ;        values for signature
  23. notLastInChain    equ    'M'
  24. LastInChain    equ    'Z'
  25.  
  26. ;        values for addressPSP
  27. freeMemory    equ    0
  28. allocatedPreDOS    equ    8
  29.  
  30. segment        memoryMangler
  31.         assume cs:memoryMangler,ds:oldBlockSeg,es:newBlockSeg
  32.  
  33. ;    IN:    dx == amount of memory to request
  34. ;    OUT:    dx == segment of new block of memory
  35. ;    OUT:    dx == 0 on error
  36. proc        hackMem far
  37.         push    ax
  38.         push    bx
  39.         push    cx
  40.         push    ds
  41.         push    es
  42.  
  43.         mov    ah,getPSP
  44.         int     21h
  45.         dec    bx    ;bx:0000 points to the MCB of the program
  46.         mov    ds,bx    ;ds:0000 points to the MCB of the program
  47.  
  48.         mov    cx,[oldBlock.blockSize]
  49.         cmp    cx,1
  50.         jbe    error
  51.         dec    cx
  52.         sub    cx,dx    ;cx is the new size of the program's main
  53.                 ;memory block
  54.         jbe    error
  55.         mov    [oldBlock.blockSize],cx
  56.  
  57.         inc    bx
  58.         add    bx,cx    ;bx:0000 points to the MCB of the new block
  59.         mov    es,bx
  60.  
  61.         mov    al,[oldBlock.signature]    ;see if this is the last
  62.                         ;block in the chain
  63.         mov    [newBlock.signature],al
  64.         mov    [oldBlock.signature],notLastInChain    ;We are
  65.                         ;certainly no longer the
  66.                         ;last in the chain
  67.  
  68.         mov    [newBlock.addressPSP],es
  69.                 ;we don't want to get rid of this block ever
  70.  
  71.         mov    [newBlock.blockSize],dx
  72.                 ;set the block size as requested
  73.  
  74.         mov    si,offset oldBlock.reserved    ;copy the standard info
  75.         mov    di,offset newBlock.reserved    ;into the new mcb
  76.         mov    cx,11
  77.     rep    movs    [newBlock.reserved],[oldBlock.reserved]
  78.  
  79.         mov    dx,es
  80.         inc    dx
  81.         jmp    done
  82.  
  83. error:        mov    dx,0
  84.  
  85. done:        pop    es
  86.         pop    ds
  87.         pop    cx
  88.         pop    bx
  89.         pop    ax
  90.         ret
  91. endp        hackMem
  92.  
  93. ends        memoryMangler
  94.  
  95.         public hackMem
  96.  
  97.         end
  98.  
  99.